<template lang="pug">
  .clearfix
    Modal(
      width="400"
      v-model="isShowCustomerTagModal"
      title= "标记客户标签"
      class-name="vertical-center-modal"
    )
      .search-form.mb-10.pr-10
        Form.ivu-row.ivu-form-basic(ref="formData" :model="formData" :rules="rules" :label-width="90")
          FormItem.form-item.ivu-col.pr-20.mb-25(v-for="(item, index) of formItem" :label="item.label" :key="index" :class="item.style" :prop="item.prop")
            template(v-if="item.type === 'select'")
              Select(v-model="formData[item.model]" :placeholder="item.placeholder" clearable filterable :disabled="item.isDisabled")
                Option(
                  v-for="(c_item, index) in arrListDown[item.options]"
                  :value="c_item.value"
                  :key="index"
                ) {{ c_item.label }}

      .clearfix(slot="footer")
        Button(type="text" @click="cancel") 取消
        Button(type="primary" @click="handleSubmit" :loading="!isCanSubmit") 确定
</template>

<script>
import HRDCCustomerApi from '@/api/HRDCCustomer.api.js'
export default {
  name: '',

  data () {
    return {
      isShowCustomerTagModal: false,
      formData: {
        tagId: '',
      },
      formItem: [
        { type: 'select', label: '客户标签：', placeholder: '请输入客户标签', prop: 'tagId', model: 'tagId', style: 'ivu-col-span-24', options: 'SalesCustomerTag' },
      ],
      rules: {
        tagId: [{ required: true, message: '请选择客户标签' }]
      },
      arrListDown: {
        SalesCustomerTag: []
      },
      isCanSubmit: true,
      parentRow: null
    }
  },

  watch: {
  },

  mounted () {
  },

  methods: {
    cancel () {
      this.isShowCustomerTagModal = false
    },

    show (row) {
      this.parentRow = row
      this.isCanSubmit = true
      this.isShowCustomerTagModal = true
      this.$refs.formData.resetFields()
    },

    async handleSubmit () {
      var params = {
        ...this.formData,
        id: this.parentRow.id
      }
      console.log('分配客户 提交表单', params)
      this.$refs.formData.validate((valid) => {
        if (valid) {
          console.log('分配客户 提交表单', params)
          HRDCCustomerApi.batchSetCustomerTag(params).then(res => {
            if (res.data.success) {
              this.isCanSubmit = false
              this.isShowCustomerTagModal = false
              this.$Message.success(res.data.message)
            } else {
              this.isCanSubmit = true
              this.$Message.error({
                content: res.data.message,
                duration: 10,
                closable: true
              })
            }
            this.$emit('query')
          })
        }
      })
    },
  }
}
</script>

<style lang="less" scope>
</style>
